package com.ys.everydaynews.ui.main.presenter

import android.util.Log
import com.ys.everydaynews.http.HttpUtils
import com.ys.everydaynews.http.ResponseListener
import com.ys.everydaynews.http.UserApi
import com.ys.everydaynews.mvp.model.BaseModel
import com.ys.everydaynews.mvp.presenter.BasePresenter
import com.ys.everydaynews.ui.main.model.CodeModel
import com.ys.everydaynews.ui.main.view.SendCodeView

class SendCodePresenter : BasePresenter<SendCodeView>() {
    fun getCode(phoneNumber:String){
        HttpUtils.sendHttp(HttpUtils.createApi(UserApi::class.java).getCode(phoneNumber),object :
            ResponseListener<BaseModel<CodeModel>> {
            override fun onSuccess(data: BaseModel<CodeModel>) {
                if (data!=null){
                    Log.e("onSuccess",data.toString())
                    getBaseView()!!.setData(data)
                }
            }

            override fun onFail(err: String) {
                Log.e("onFail",err)
                getBaseView()!!.setError(err)
            }

        })
    }
    fun postCode(phoneNumber:String){
        HttpUtils.sendHttp(HttpUtils.createApi(UserApi::class.java).getCode(phoneNumber),object :
            ResponseListener<BaseModel<CodeModel>> {
            override fun onSuccess(data: BaseModel<CodeModel>) {
                if (data!=null){
                    Log.e("onSuccess",data.toString())
                    getBaseView()!!.setRegisterData(data)
                }
            }

            override fun onFail(err: String) {
                Log.e("onFail",err)
                getBaseView()!!.setRegisterError(err)
            }

        })
    }
}